package com.leyou.item.controller;

import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping
public class SpecController {
    @Autowired
    private SpecService specService;

    /**
     * 根据类别查询规格组
     * @param id
     * @return
     */
    @GetMapping("/spec/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>>findSpecGroupByCid(@RequestParam("id") Long id){
        List<SpecGroupDTO>list= specService.findSpecGroupByCid(id);
        return ResponseEntity.ok(list);
    }

    /**
     * 根据规格组查询规格参数
     * @param cid
     * @param gid
     * @param searching
     * @return
     */
     @GetMapping("/spec/params")
    public  ResponseEntity<List<SpecParamDTO>>findSpecParam
             (@RequestParam(value = "cid",required =false)Long cid,
              @RequestParam(value = "gid",required =false)Long gid,
              @RequestParam(value = "searching",required =false)Boolean searching){
         List<SpecParamDTO>list= specService.findSpecParam(cid,gid,searching);
         return ResponseEntity.ok(list);

     }

     //根据spu中第三级商品分类查询出规格组集合及其下规格参数集合
     @GetMapping("/spec/groups/of/category/params")
     public ResponseEntity<List<SpecGroupDTO>> findSpecGroupWithParamsByCid(@RequestParam("id") Long id){
         List<SpecGroupDTO> list = specService.findSpecGroupWithParamsByCid(id);
         return ResponseEntity.ok(list);
     }
}
